/*
 *  Copyright (C) 2009  Peter Kist & Jan Ripke
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "SettingsMenu.h"

#include <core/Logger.h>
#include <gfx/ogre/Types.h>
#include <gfx/ogre/gui/MenuHelper.h>
#include <gfx/ogre/gui/MenuManager.h>

#include <CEGUIWindowManager.h>
#include <CEGUIEventArgs.h>
#include <elements/CEGUIPushButton.h>
#include <elements/

namespace galaxy {
    namespace gfx {
        namespace ogre3d {
            namespace menu {

                SettingsMenu::Name SettingsMenu::c_MainMenuButton = "MainMenu";
                SettingsMenu::Name SettingsMenu::c_ActionListBox  = "tab/keys/actions";

                bool SettingsMenu::load () {
                    LOG_TRACE ("loading menu SettingsMenu");
                    m_Window = 
                        CEGUI::WindowManager::getSingleton().loadWindowLayout("settings.layout", "", "GUI");
                    return false;
                }

                bool SettingsMenu::setup () {
                    LOG_TRACE ("setup menu SettingsMenu");

                    CEGUI::WindowManager& winMngr = CEGUI::WindowManager::getSingleton();

                    gui::MenuHelper::pushButtonClick (&SettingsMenu::MainMenu_OnClick, this, c_MainMenuButton);

                    /*
                    CEGUI::PushButton * mainMenu = 
                        (CEGUI::PushButton *) winMngr.getWindow(c_MainMenuButton);
                    mainMenu->subscribeEvent (CEGUI::PushButton::EventClicked,
                        CEGUI::Event::Subscriber (&SettingsMenu::MainMenu_OnClick, this));
                    */

                    // FIXME: move this to action listbox
                    CEGUI::Listbox * actionList =
                        (CEGUI::Listbox *) winMngr.getWindow(c_ActionListBox);
                    CEGUI::ListboxItem * item;
                    item = new CEGUI::ListboxTextItem();
                    item->


                    CEGUI::System::getSingleton().setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook",
                        (CEGUI::utf8*)"MouseArrow");
                    const CEGUI::Image * mouseImage = CEGUI::System::getSingleton().getDefaultMouseCursor();
                    CEGUI::MouseCursor::getSingleton().setImage(mouseImage);

                    return true;
                }

                bool SettingsMenu::unload () {
                    
                    if (m_Window) {
                        LOG_TRACE ("unloading menu SettingsMenu");
                        CEGUI::WindowManager::getSingleton().destroyWindow(m_Window);
                        m_Window = 0L;
                    }
                    return false;
                }

                bool SettingsMenu::MainMenu_OnClick(const CEGUI::EventArgs &args) {
                    return changeState (logic::State::c_MainMenu);
                }

            } // namespace menu
        } // namespace ogre3d
    } // namespace gfx
} // namespace galaxy
